﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="persondoc_mydoc_tree.aspx.cs" Inherits="Ccit.OA.PersonDoc.persondoc_mydoc_tree" %>
<%@ Register Assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="Microsoft.Web.UI.WebControls" TagPrefix="iewc" %>
    
<%@ Register TagPrefix="ccit" Namespace="Ccit.ServerControls" Assembly="Ccit.ServerControls.ActionForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <link href="css/enter.css" rel="stylesheet" type="text/css">
       <script language="javascript" src="../script/jquery.js" type="text/javascript"></script>
    <script language="javascript" src="../script/jbase64.js" type="text/javascript"></script>
    <script language="javascript" src="../script/jsonlib.js" type="text/javascript" ></script>
    <script language="javascript" src="../script/StringClass_Ext.js" type="text/javascript" ></script>
    <style>
		.skin { BORDER-RIGHT: buttonhighlight 2px outset; BORDER-TOP: buttonhighlight 2px outset; FONT-SIZE: 9pt; VISIBILITY: hidden; BORDER-LEFT: buttonhighlight 2px outset; WIDTH: 100px; CURSOR: default; BORDER-BOTTOM: buttonhighlight 2px outset; FONT-FAMILY: Arial, Helvetica, sans-serif; POSITION: absolute; BACKGROUND-COLOR: menu; TEXT-ALIGN: left }
		.menuitems { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-TOP: 5px; PADDING-BOTTOM: 5px;}
	</style>
</head>
<body>
    <ccit:ActionForm id="form1" runat="server">
    
    
    <input type="hidden" id="_hidNodeTab" runat="server" />
    
    <input type="hidden" id="_hidClassType" runat="server" />
    <input type="hidden" id="_hidSysDocId" runat="server" />
    
    
    <input type="hidden" id="_hidOriUpAddrId" runat="server" />
    <input type="hidden" id="_hidUpAddrId" runat="server" />  
    <input type="hidden" id="_hidAddNewSign" runat="server" /> <!-- 新增记录标志 -->
    <input type="hidden" id="_hidDelAddressId" runat="server" />  
    
    <input type="hidden" id="_hidShare" runat="server" />    <!-- 共享标志 -->  
        <!--保存后传来的主键id-->
    <input type="hidden" id="_hidNewColumnId" runat="server" />
    <input type="hidden" id="_hidExpandSign" runat="server" />
    <input type="hidden" id="_hidLevelStruct" runat="server" />
    
    
            <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" />
    <table cellspacing="0" cellpadding="0" align="center" border="0"  style="WIDTH:98%;HEIGHT:100%">
			<tr  valign="top">
				<td id="Td1"   style="background-color:#EEF2F7; border:0px solid #999999" runat="server">
        <iewc:TreeView ID="trvperson" runat="server"></iewc:TreeView>
                
   <br />
  <!--编辑页面保存成功的时候  调用的事件-->
    <input type="button" id="btnTrigger" onclick="doTrigger()" style="display:none" value="触发事件" />
    <!--编辑页面删除成功的时候  调用的事件-->
    <input type="button" id="btnDelTrigger" onclick="doDelTrigger()" style="display:none" value="删除触发事件" />
    
    		</td>
		    </tr>
		</table>
		
		<script type="text/javascript">
    <!--
        var menuskin = "skin";
		var node = null;
		var menuname = "root";	 
		 
		function hideMenu() 
		{		    
			var obj = document.getElementById(menuname);
			if (null != obj && typeof(obj) != "undefined")
				document.getElementById(menuname).style.visibility = "hidden";
		}
		function highlighItem() 
		{
			if (event.srcElement.className == "menuitems") 
			{
				event.srcElement.style.backgroundColor = "highlight";
				event.srcElement.style.color = "white";
			}
		}
		function lowlightItem() 
		{
			if (event.srcElement.className == "menuitems") 
			{
				event.srcElement.style.backgroundColor = "";
				event.srcElement.style.color = "black";
				window.status = "";
			}
		}

		      //编辑页面保存成功的时候  调用的方法
        function doTrigger() {		
                 var isAddNew = $get("_hidAddNewSign").value;   //是否为编辑 1:新增 2:更新  ;  Code复制/Shear剪切
                 if(isAddNew == "1" || isAddNew == "2") {    
		            doOperOriParentNode();//对文件夹操作时  更新或新增节点
		         }
		         else {
		            doOperCoShOriNode();
		         }
		}
		
		function doOperCoShOriNode() {
		    var vUpTypeId = $get("_hidUpAddrId").value;		 //新父节点的主键(绑定到树节点的主键)
		    var isAddNew = $get("_hidAddNewSign").value;   //是否为编辑  Code复制/Shear剪切
		    var NodeExpr = $get("_hidNewColumnId").value;   //获取的是当前编辑的节点对象 eg:{"FId":"26","FName":"测试类型","Superiorid":"1"}
		    eval("var NodeObj=" + NodeExpr);	    //获取节点消息对象	
		      
		    var vFoldNode;    //上级文件夹节点对象
		    var vDtNodeIndex; //节点索引
		    
		    /* 获取新上级节点对象 */
		    if(vUpTypeId != "") {		        
		        vFoldNode = findTreeNode(vUpTypeId);	  //新上级节点对象	
		        if(null == vFoldNode) {    //找不到新父节点
		            //alert("数据有误,无法找到上级文件夹");
		            return;
		        }
		        vDtNodeIndex = vFoldNode.getNodeIndex();	
		    }
		    else {	
		        vFoldNode=ctrlRoot;	
		        vDtNodeIndex= "0";  
		    } 
		    
		    
		    if(isAddNew == "Code")
		    {
		       createSubTNodes(vDtNodeIndex,NodeObj);
		    }
		    else{
		            
		            $get("_hidDelAddressId").value = NodeObj.FId;
		            $get("_hidClassType").value = NodeObj.FType;
		            doDelTrigger();
                    createSubTNodes(vDtNodeIndex,NodeObj);
		    }
		    NodeObj = null;
		    vFoldNode.setAttribute("EXPANDED",true);
		    return;
		}
		
		//找原父节点
		function doOperOriParentNode() {
		    var vOriUpTypeId = $get("_hidOriUpAddrId").value; //原父节点的主键(绑定到树节点的主键)
		    var vUpTypeId = $get("_hidUpAddrId").value;		 //新父节点的主键(绑定到树节点的主键)
		    var isAddNew = $get("_hidAddNewSign").value;   //是否为编辑 1:新增 2:更新
		    
		        
		    if(isAddNew=="2"){//更新
		       //原节点与新节点相等
		            var NodeExpr = $get("_hidNewColumnId").value;   //获取的是当前编辑的节点对象 eg:{"FId":"26","FName":"测试类型","Superiorid":"1"}
		            eval("var NodeObj=" + NodeExpr);	    //获取节点消息对象	           
		            var colName = NodeObj.FName;
		            var ClickObj = findTreeNode(NodeObj.FId);		
		            ClickObj.setAttribute("Text",colName);
		            
		            /*判断是否为共享，取消共享时应删除*/
		            ClickObj = findTreeNodeShare(NodeObj.FId);
		            var isShare = $get("_hidShare").value;     //共享标志 -1为共享 ""为不共享
		            if(isShare == "-1"){
		                if(ClickObj != null) {
		                    ClickObj.setAttribute("Text",colName);
		                }
		                else {
		                    doShareDtParentNode();    
		                }
		            }
		            else{
		                if(ClickObj != null) {
		                    ClickObj.remove();  //移除
		                }
		            }
		            		
		            return;
		        /* 初始化全局变量 */
		        ctrlOgNode = null;		    
		        vOgNodeIndex = "";
		        // get root node object
		        var ctrlTree = document.getElementById("trvperson");	
		        var ctrlRoot = ctrlTree.getTreeNode("0");
    		    
		        /* 获取原始上级节点对象 */
		        //根据原父节点主键获取其树的节点索引(eg：根据点击树主键3，获取其树的索引0.1)
		        if(vOriUpTypeId != ""&&vOriUpTypeId!="0") {
		            ctrlOgNode = findTreeNode(vOriUpTypeId);  //根据原父节点主键获取其树的节点对象 
		            vOgNodeIndex = ctrlOgNode.getNodeIndex();  //根据节点对象获取树节点索引eg:0.0.1
		        }
		        else {   //无上级父节点时
		            ctrlOgNode=ctrlRoot;  
		            vOgNodeIndex= "0";
		        }
		        var curNodeExpr = $get("_hidNewColumnId").value;   //获取的是当前编辑的节点对象 eg:{"FId":"26","FName":"测试类型","Superiorid":"1"}
		        eval("var folderNodeObj=" + folderNodeExpr);
                // find current node position index
                var folderNode = findTreeNode(folderNodeObj.FId);  //获取当前编辑节点对象对应的树节点对象
                
                // delete origin node
                folderNode.remove();  //移除
                
                folderNodeObj = null;
		    }
		    else
		    {
		        doOperDtParentNode();
		        doShareDtParentNode();   //我的共享
		    }
		    return;		    
		}
		
		
		    function recursionFind(ctrlChildNodes,findAddrId) {
            var iLen = ctrlChildNodes.length;
            var ctrlTreeNode;
		    var vNodeId;
		    var vNodeIdArray;
		    var vAddressId;
		    var ctrlSubChildNodes;
		    var bFind = false;
		    
            for(var i = 0; i < iLen; i ++) {
		        ctrlTreeNode = ctrlChildNodes[i];
		       vNodeId = ctrlTreeNode.getAttribute("ID");    
		        if(vNodeId == findAddrId) {		           
		            bFind = true;
		            break;       
		        }
		        else {
		            ctrlSubChildNodes = ctrlTreeNode.getChildren();
		            ctrlTreeNode = recursionFind(ctrlSubChildNodes,findAddrId);
		            if(null != ctrlTreeNode) {
		                bFind = true;
		                break;
		            }
		                
		        }
		    }
            
            if(bFind)
                return ctrlTreeNode;
            else
                return null;
        } 
        
        function doShareDtParentNode(){
            var isShare = $get("_hidShare").value;     //共享标志 -1为共享 ""为不共享
             var vUpTypeId = $get("_hidUpAddrId").value;		//新的上级节点    
		    var isAddNew = $get("_hidAddNewSign").value; //是否为编辑 1:新增 2:更新
		     var folderNodeExpr = $get("_hidNewColumnId").value;
		    eval("var folderNodeObj=" + folderNodeExpr);
		    
		    
             if(isShare == "-1"){
                createSubTNodes("0.1",folderNodeObj);
                $get("_hidShare").value = "";
             }
            
        }
		//找新父节点
		function doOperDtParentNode() {
		    var vOriUpTypeId = $get("_hidOriUpAddrId").value;  
		    var vUpTypeId = $get("_hidUpAddrId").value;		//新的上级节点    
		    var isAddNew = $get("_hidAddNewSign").value; //是否为编辑 1:更新 2:新增
		    
		    /* 初始化全局变量 */
		    ctrlDtNode = null;		    
		    vDtNodeIndex = "";
		    // get root node object
		    var ctrlTree = document.getElementById("trvperson");	
		    var ctrlRoot = ctrlTree.getTreeNode("0");
		    /* 获取新上级节点对象 */
		    if(vUpTypeId != "") {		        
		        ctrlDtNode = findTreeNode(vUpTypeId);	  //新上级节点对象	
		        if(null == ctrlDtNode) {    //找不到新父节点
		            expandDtNode(vUpTypeId);
		            return;
		        }
		        vDtNodeIndex = ctrlDtNode.getNodeIndex();	
		        var ctrlSubChildNodes = ctrlDtNode.getChildren();
		        var iChildLength = ctrlSubChildNodes.length;
		        
		        var bHasChild = false;
		        if(iChildLength > 0)
		           bHasChild = true;		    
		    }
		    else {	
		        ctrlDtNode=ctrlRoot;	
		        vDtNodeIndex= "0";  
		    } 
		    var curNodeExpr = $get("_hidNewColumnId").value;
		    eval("var curNodeObj=" + curNodeExpr);
		               
            // add node to destination parent node	
              createSubTNodes(vDtNodeIndex,curNodeObj);

		    ctrlDtNode.setAttribute("EXPANDED",true);
		    curNodeObj = null;
		}
		
		
		        //追加子节点
        function createSubTNodes(nodeIndex,oResult) { 
		     var sParam1;
		     var encodeParam1;
		     var sfiesId= new Array(); 
	         var sfiesType= new Array(); 
	         var sfiesName = new Array();
	         
	         		   
		    sfiesId = oResult.FId.split(",");
		    sfiesType = oResult.FType.split(",");
		    sfiesName = oResult.FName.split(",");
	         
		     var node = $get("trvperson").getTreeNode(nodeIndex);
            for(var i=0;i<sfiesId.length;i++)
            {
                if(sfiesType[i] == "") {
         	         sParam1 = "folderID=" + sfiesId[i] + "&folderType=" + "0";
                     var encodeParam1 = base64encode(sParam1);
                     vNavigateUrl = "./persondoc_mydoc_list.aspx?"+encodeParam1;
                     oSubNode = $get("trvperson").createTreeNode();
                     oSubNode.setAttribute("ID",sfiesId[i]);
                     oSubNode.setAttribute("Text",sfiesName[i]);
                     oSubNode.setAttribute("Type","root");
                     oSubNode.setAttribute("Target","iFrmEdit");
                     oSubNode.setAttribute("ImageUrl","../images/toolbar/folder_open.gif");
                     oSubNode.setAttribute("NavigateUrl",vNavigateUrl);
    		         
                     if(oResult.State == "1") {  //if contain sub node then add empty node
                       oEmptyNode = $get("trvperson").createTreeNode();  
                       oSubNode.add(oEmptyNode); 
                     }
                     node.add(oSubNode);
                    /* set node load sign = 1 */
                    var vNodeId = node.getAttribute("ID");
	                sfiesId[i] = vNodeId;
	                node.setAttribute("ID",sfiesId[i]);	
	            }
            }    
        }
        
        
		
		
		//编辑页面删除成功的时候  调用的方法
		function doDelTrigger() {
		    var delfiesId= new Array(); 
		    var delfiesType= new Array(); 
		    var folderNode;	   
		   
		    delfiesId = $get("_hidDelAddressId").value.split(",");
		    delfiesType = $get("_hidClassType").value.split(",");
		    
		    for (i=0;i<delfiesId.length ;i++ )      
		    { 
		        if(delfiesType[i] == "")
		        {
	                folderNode = findTreeNode(delfiesId[i]);
	                if(folderNode != null)
	                {
	                    nodeIndex = folderNode.getNodeIndex();
	                    var node = $get("trvperson").getTreeNode(nodeIndex); 
                        node.remove(); 
                    }
                    
                    folderNode = findTreeNodeShare(delfiesId[i]);
                    if(folderNode != null)
                    {
                        nodeIndex = folderNode.getNodeIndex();
                        var node = $get("trvperson").getTreeNode(nodeIndex); 
                        node.remove(); 
                    }
                    
                    folderNode = findTreeNodeOtherShare(delfiesId[i]);
                    if(folderNode != null)
                    {
                        nodeIndex = folderNode.getNodeIndex();
                        var node = $get("trvperson").getTreeNode(nodeIndex); 
                        node.remove(); 
                    }
                }
                
            }         
		}
		
		        ///查找节点
        function findTreeNode(findAstTypeId) {
            var ctrlTree = document.getElementById("trvperson");		    
		    
		    var ctrlRoot = ctrlTree.getTreeNode("0"); 
		    var ctrlChildNodes = ctrlRoot.getChildren();
	    
		    var ctrlFindNode = recursionFind(ctrlChildNodes,findAstTypeId);
            return ctrlFindNode;

        }
        
         function findTreeNodeShare(findAstTypeId) {
            var ctrlTree = document.getElementById("trvperson");		    
		    
		    var ctrlRoot = ctrlTree.getTreeNode("0.1"); 
		    var ctrlChildNodes = ctrlRoot.getChildren();
	    
		    var ctrlFindNode = recursionFind(ctrlChildNodes,findAstTypeId);
            return ctrlFindNode;

        }
        
            function findTreeNodeOtherShare(findAstTypeId) {
            var ctrlTree = document.getElementById("trvperson");		    
		    
		    var ctrlRoot = ctrlTree.getTreeNode("0.1.0"); 
		    if(ctrlRoot == null)
		    {return null;}
		    else
		    {
		        var ctrlChildNodes = ctrlRoot.getChildren();
    	    
		        var ctrlFindNode = recursionFind(ctrlChildNodes,findAstTypeId);
    		    
                return ctrlFindNode;
            }

        }
        //-->
		</script>
    </ccit:ActionForm>
</body>
</html>
